; The complex system is divided into multiple modules, 
; and each module can be explained independently.

; (define (<name> a b)
;     (if (> a b)
;     0
;     (+ <term> a)
;     (<name> (<next> a) b)))

; Procedure as parameter

(define (sum term a next b)
    (if (> a b)
    0
    (+ (term a)
    (sum term (next a) next b))))

; iteration method

; (define (sum term a next b)
;     (define (iter j ans)
;         (if(> j b)
;         ans
;         (iter (next j)
;             (+ (term j) ans))))
;     (iter a 0))

(define (pi-sum a b)
    (sum (lambda (i) (/ 1.0 (* i (+ i 2))))
        a
        (lambda (i) (+ i 4))
        b))

(pi-sum 1 8)

